package net.lainiao.workqueuenofiare;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DefaultConsumer;
import com.rabbitmq.client.Envelope;
import net.lainiao.MyConst;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * Created by Administrator on 2018/7/9.
 */
public class CustomDemo2 {
    public static void main(String[] args) throws IOException, TimeoutException, InterruptedException {
            final Channel channel= MyConst.getChanel();
            channel.queueDeclare(MyConst.QName1,false,false,true,null);
            channel.basicConsume(MyConst.QName1,true,new DefaultConsumer(channel){
                @Override
                public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                    System.out.println("2接受到消息:"+new String(body));
                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            });
            Thread.sleep(1000000000);
    }
}
